package fr.fonzie.javac;

import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.NOTE;
import static javax.tools.Diagnostic.Kind.WARNING;

import javax.annotation.processing.ProcessingEnvironment;

import com.sun.source.util.Trees;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Name.Table;

public class SunJavacContext
{
    public Trees trees;

    public TreeMaker maker;

    public Name.Table names;

    private ProcessingEnvironment env;

    public SunJavacContext( ProcessingEnvironment env )
    {
        this.env = env;
        this.trees = Trees.instance( env );
        // Let's hack the SUN Javac
        JavacProcessingEnvironment javac = (JavacProcessingEnvironment) env;
        Context context = javac.getContext();
        this.maker = TreeMaker.instance( context );
        this.names = Table.instance( context );
    }

    public Name fromString( CharSequence arg0 )
    {
        return names.fromString( arg0 );
    }

    public void note( String msg )
    {
        env.getMessager().printMessage( NOTE, msg );
    }

    public void warn( String msg )
    {
        env.getMessager().printMessage( WARNING, msg );
    }

    public void error( String msg )
    {
        env.getMessager().printMessage( ERROR, msg );
    }
}
